import {Message} from "element-ui";

const commonSDK = {
    /**
     *  @desc  获取设备的信息
     *  queueLen:队列的长度
     *  switchTime:切屏等待的时间（秒）
     * **/
    deviceInfoAction: (queueLen,switchTime) => {
        try {
            console.log('获取设备的基本的信息')
            let dataInfo = Object();
            //切屏队列数量
            Reflect.set(dataInfo,'queueLen',queueLen);
            //切屏间隔（秒）
            Reflect.set(dataInfo,'switchSeconds',switchTime);
            // 按照安卓的要求 定义对象(对象包含:请求的参数/回调函数[安卓返回数据])
            let obj = Object();
            Reflect.set(obj,'action','DeviceInfoAction');
            Reflect.set(obj,'callback','deviceCallback');
            Reflect.set(obj,'data',JSON.stringify(dataInfo));
            window.native.handleMessage(JSON.stringify(obj));
        } catch (e) {
            // console.log('writeLog-->' + message);
        }
    },

    // 通知安卓
    AndroidUpdateWaitData: () => {
        try {
            let obj = Object();
            // 按照安卓的要求 定义对象(对象包含:请求的参数/回调函数[安卓返回数据])
            Reflect.set(obj,'action','QueueSwitchAction');
            Reflect.set(obj,'callback','');
            Reflect.set(obj,'data','');
            window.native.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    },

    // 前端日志
    WebLogAction: (data = {}) => {
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'CommonAction');
            Reflect.set(obj, 'callback', '');
            Reflect.set(obj, 'bizFun', 'setHtmlLog');
            Reflect.set(obj, 'data', data);
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog-->${err}`);
        }
    },

    // 桐乡前端-安卓-服务端通道
    WebToAndroidRep: (data=  {},callback) => {
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'CommonAction');
            Reflect.set(obj, 'callback', callback);
            Reflect.set(obj, 'bizFun', 'sendSocketData');
            Reflect.set(obj, 'data', data);
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    },

    // 打开扫码
    WebToAndroidOpenScan: (data=  {}) => {
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'ReportMachineAction');
            Reflect.set(obj, 'callback', 'cardInfoCallBack');
            Reflect.set(obj, 'bizFun', 'readCardNoLimit');
            Reflect.set(obj, 'data', '');
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    },

    // 关闭扫码
    WebToAndroidCloseScan: (data = {}) => {
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'ReportMachineAction');
            Reflect.set(obj, 'callback', '');
            Reflect.set(obj, 'bizFun', 'cancelReadCard');
            Reflect.set(obj, 'data', '');
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    },

    // 读取电子医保码
    WebToAndroidMICode:()=>{
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'ReportMachineAction');
            Reflect.set(obj, 'callback', 'cardInfoCallBack');
            Reflect.set(obj, 'bizFun', 'readMedicalQrCode');
            Reflect.set(obj, 'data', '');
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    },

   // 设备Ip&设备id
    WebToAndroidDevInfo:()=>{
        try {
            let obj = Object();
            Reflect.set(obj, 'action', 'CommonAction');
            Reflect.set(obj, 'callback', 'deviceInfo');
            Reflect.set(obj, 'bizFun', 'deviceInfo');
            Reflect.set(obj, 'data', '');
            window.android.handleMessage(JSON.stringify(obj));
        } catch (err) {
            console.log(`writeLog:${err}`);
        }
    }

};


export default commonSDK;